var EPGSilder = Class.create(EpgWidget,{
	initialize: function($super, id, opts, links) {
        $super(id,opts,links);
        //this.setInitTitle();
        this.order = opts.order;
        this.size = opts.size;
        this.current = 0;
        this.findBackItem();
        this.timer = null;
        this.autorotation();
    },
    ok: function(){
    	var url = this.opts.list[this.current].url;
    	url = EPG.appendParam(url, 'lps', this.current);
    	EPG.gotoPage(url,this.opts.list[1].id);
    },
	left: function() {
		var newOrder = new Array();
		for(var i = 0; i < this.size; i++) {
			if(i == 0) {
				newOrder[i] = this.order[this.size - 1];	
			} else {
				newOrder[i] = this.order[i - 1];
			}
		}
		this.order = newOrder;
		this.render();
	},
	right: function() {
		var newOrder = new Array();
		for(var i = 0; i < this.size; i++) {
			if(i == this.size - 1) {
				newOrder[i] = this.order[0];	
			} else {
				newOrder[i] = this.order[i + 1];
			}
		}
		this.order = newOrder;
		this.render();
	}	,
	render: function() {
		var tempSrcArr = new Array();
		for(var i = 0; i < this.size; i++) {
			document.getElementById(this.opts.divId + i + "_img").src = this.opts.list[this.order[i]].icon;
		}
		this.current = this.order[1];
		if(this.opts.onchange){
			this.opts.onchange.call(this,this.current);
		}
	},
	onkeypress: function(ev) {
	  if(this.opts.keypress){
		  result = this.opts.keypress.call(this,ev);
		  if(result){
			  return true;
		  }
	  }
	  if(ev.keyCode==KEY_ENUM.KEY_OK){
		  this.ok();
		  return true;
	  }else if(ev.keyCode==KEY_ENUM.KEY_RIGHT){
		  this.right();
		  return true;
	  }
	  return false;
	},
	autorotation: function() {
		var self = this;
		this.timer = window.setInterval(function() {
			self.left();
		}, 5000);
	},
	stop:function(){
		clearInterval(this.timer);
	},
	findBackItem: function() {
		var lSilderId = this.opts.lSilderId;
		if(lSilderId == ''){
			return;
		}
		var step = 0;
		for(var i = 0; i < this.size; i++) {
			if(this.opts.list[this.order[i]].id == this.opts.list[lSilderId].id) {
				step = i - (this.size - this.size % 2) / 2;
				break;
			}
		}
		var newOrder = new Array();
		for(var i = 0; i < this.size; i++) {
			var index = i + step;
			if(index > this.size - 1) {
				index -= this.size;	
			} else if(index < 0) {
				index += this.size;
			}
			newOrder[i] = this.order[index];
		}
		this.order = newOrder;
		this.render();
	},
	setInitTitle: function() {
		document.getElementById(this.opts.titleId + "text").innerHTML = this.opts.list[0].title;
	}
} ); 